package com.uranus.rancher.rancher.service.impl;


import com.baomidou.mybatisplus.core.conditions.Condition;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uranus.common.VO.ServiceContext;
import com.uranus.common.constant.enums.LanguageEnum;
import com.uranus.rancher.rancher.request.RancherQueryRequest;
import com.uranus.common.VO.Result;
import com.uranus.common.VO.paging.Paginator;
import com.uranus.common.VO.paging.PagingRequest;
import com.uranus.rancher.rancher.beans.Rancher;
import com.uranus.rancher.rancher.mapper.RancherMapper;
import com.uranus.rancher.rancher.service.RancherService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wei_yzh
 * @since 2018-12-10
 */
@Service
public class RancherServiceImpl extends ServiceImpl<RancherMapper, Rancher> implements RancherService {

    @Override
    public Result searchRancher(PagingRequest<RancherQueryRequest> request) {
        Paginator paginator = request.getPaginator();
        RancherQueryRequest queryRequest = request.getSelector();
        Page<Rancher> page = new Page<>(paginator.getPage(), paginator.getPageSize());
        QueryWrapper<Rancher> queryWrapper = new Condition().create();
        if (StringUtils.hasLength(queryRequest.getRegion())) {
            queryWrapper.like("region",  request.getSelector().getRegion() );
        }

        IPage<Rancher> pageInfo = this.baseMapper.selectPage(page, queryWrapper);

        for (Rancher item:pageInfo.getRecords()){
            if(ServiceContext.getInstance().getLanguageEnum()== LanguageEnum.en_us){
                item.setRegion(item.getRegionEnUs());
            }




        }
        return Result.buildSuccess(pageInfo);
    }
}
